package com.ruoyi.weixin.mp.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.weixin.mp.entity.vo.MsgTemplateVo;
import com.ruoyi.weixin.mp.utils.Json;
import lombok.Data;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;

import java.io.Serializable;
import java.util.Date;

/**
 * 模板消息模板
 * @author Nifury
 * @date 2017-9-27
 */
@Data
@TableName("wx_msg_template")
public class MsgTemplate implements Serializable {

    private static final long serialVersionUID = 1L;
    private Long id;
    private String appid;
	@TableId(type = IdType.INPUT)
    private String templateId;
    private String name;
    private String title;
    private String content;

    private String data;
    private String url;
    private String miniprogram;
    private boolean status;
    private Date updateTime;
    public MsgTemplate() {

    }
    public MsgTemplate(WxMpTemplate mpTemplate,String appid) {
        this.appid = appid;
        this.templateId=mpTemplate.getTemplateId();
        this.title=mpTemplate.getTitle();
        this.name=mpTemplate.getTemplateId();
        this.content = mpTemplate.getContent();
        this.status=true;
    }

    public MsgTemplate(MsgTemplateVo msgTemplateVo){
        this.id = msgTemplateVo.getId();
        this.appid = msgTemplateVo.getAppid();
        this.templateId = msgTemplateVo.getTemplateId();
        this.name = msgTemplateVo.getName();
        this.title = msgTemplateVo.getTitle();
        this.content = msgTemplateVo.getContent();
        this.data = JSONArray.toJSONString(msgTemplateVo.getData());
        this.url = msgTemplateVo.getUrl();
        this.miniprogram = JSONObject.toJSONString(msgTemplateVo.getMiniprogram());
        this.status = msgTemplateVo.isStatus();
        this.updateTime = new Date();
    }

}
